package com.appprogram.baseapppackage.widget;

import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.webkit.WebView;

/**
 * Created by Android Studio .
 * Project：SixPulsesPackage com.sixpulsespackage.union
 * Date：2019/5/23 8:57
 * Introduce：SixPulsesPackage
 */
class LoadRule {
    static boolean loadRule(WebView view, String url) {
        Log.e("这是监听url的方法 URL：", url);
        if (url.startsWith("tel:")) {
            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
            view.getContext().startActivity(intent);
            return true;
        } else if (url.startsWith("weixin://") || url.startsWith("alipay") || url.startsWith("baidu")) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            view.getContext().startActivity(intent);
            return true;
        } else if (!url.contains("alipay") && !url.contains("wx") && !url.contains("weixin")
                && !url.contains("type") && !url.contains("amap")) {
            //if (!url.contains("?")) url = url + "?isApp=1";
            //else url = url + "&isApp=1";
            view.loadUrl(url);
        }
        Log.e("这是拼接后的URL：", url);
        //如果已经登陆、则有这个is_login 字段，清空webView历史页面
        if (url.contains("is_login")) view.clearHistory();
        return false;
    }
}
